package com.lysh.aliHttp;

import com.lysh.aliHttp.common.ExecutionContext;
import com.lysh.aliHttp.common.HttpMesssage;
import com.lysh.aliHttp.common.RequestMessage;
import com.lysh.aliHttp.common.ResponseMessage;
import com.lysh.aliHttp.common.enums.HttpMethod;
import com.lysh.aliHttp.common.exception.ClientException;
import com.lysh.aliHttp.common.exception.ServiceException;
import com.lysh.aliHttp.utils.CodingUtils;
import com.lysh.aliHttp.utils.LogUtils;

import java.io.IOException;

/**
 * @author liyishan
 * @date 2023/5/5 09:13
 * @apiNote
 */

public abstract class ServiceClient {
    protected ClientConfiguration config;

    protected ServiceClient(ClientConfiguration config) {
        this.config = config;
    }

    public ClientConfiguration getClientConfiguration() {
        return this.config;
    }


    public ResponseMessage sendRequest(RequestMessage request, ExecutionContext context) throws ServiceException, ClientException {
        CodingUtils.assertParameterNotNull(request, "request");
        CodingUtils.assertParameterNotNull(context, "context");

        ResponseMessage var3;
        try {
            var3 = null;
                    //this.sendRequestImpl(request, context);
        } finally {
            try {
                request.close();
            } catch (IOException var10) {
                LogUtils.logException("Unexpected io exception when trying to close http request: ", var10);
                throw new ClientException("Unexpected io exception when trying to close http request: ", var10);
            }
        }

        return var3;
    }





    public static class Request extends HttpMesssage {
        private String uri;
        private HttpMethod method;
        private boolean useUrlSignature = false;
        private boolean useChunkEncoding = false;

        public Request() {
        }

        public String getUri() {
            return this.uri;
        }

        public void setUrl(String uri) {
            this.uri = uri;
        }

        public HttpMethod getMethod() {
            return this.method;
        }

        public void setMethod(HttpMethod method) {
            this.method = method;
        }

        public boolean isUseUrlSignature() {
            return this.useUrlSignature;
        }

        public void setUseUrlSignature(boolean useUrlSignature) {
            this.useUrlSignature = useUrlSignature;
        }

        public boolean isUseChunkEncoding() {
            return this.useChunkEncoding;
        }

        public void setUseChunkEncoding(boolean useChunkEncoding) {
            this.useChunkEncoding = useChunkEncoding;
        }
    }

}
